<template>
  <yt-page title="新增指令">
    <yt-cell label="执行时间">
      <yt-cell-time format="YYYY-MM-DD hh:mm:ss" v-model="form.Time"></yt-cell-time>
    </yt-cell>
    <yt-textarea title="执行步骤" type="column" v-model="form.context"></yt-textarea>
    <yt-card title="上传附件" :tag="false">
      <yt-file :uploadFile="uploadFile" v-model="form.file"></yt-file>
    </yt-card>
    <yt-btn @click="submit" class="m-t">提交</yt-btn>
  </yt-page>
</template>

<script>
import { EVENTS, BUS } from '@/store'
import { commonApi } from '@/common/api/commonApi.js'

export default {
  data() {
    return {
      id: '',
      form: {
        Time: '',
        context: '',
        file: []
      },
      uploadFile: file =>
        commonApi
          .uploadFile(file)
          .then(({ _name, _url }) => ({ name: _name, url: _url }))
    }
  },
  methods: {
    submit() {
      BUS.$emit(EVENTS.emergencyCommandActionAdd, this.form)
      this.form = {
        Time: '',
        context: '',
        file: []
      }
      this.$router.$back()
    }
  }
}
</script>
